#include"processbar.h"
#include<string.h>

const char* symbol="|/-\\";
char pro[100] = "\0";
void processbar(int speed)
{
  int cnt = 0;
  while(cnt<=100)
  {
    int len = strlen(symbol);

    printf("[%-100s][%-2d%%][%c]\r",pro,cnt,symbol[cnt%len]);
    fflush(stdout);
    pro[cnt++]=STYLE;
    if(cnt <100 )pro[cnt]='>';
    usleep(speed);
    
  }
  printf("\n");
}

void processbar2(int rate)
{
  if(rate<0 || rate>100)
    return;
    int len = strlen(symbol);

    printf("[%-100s][%-2d%%][%c]\r",pro,rate,symbol[rate%len]);
    fflush(stdout);
    pro[rate++]=STYLE;
    if(rate <100 )pro[rate]='>';

}
void Initbar()
{
  memset(pro,'\0',sizeof(pro));
}
